
import { defineAsyncComponent } from 'vue'

/**
 * import svgIcon from './svg-icon/index.vue'
 * import search from './search/index.vue'
 */


export default {
  install(app) {
    /**
     * app.component('m-svg-icon',svgIcon)
     * app.component('m-search',search)
     */

    /**
     * 1. 获取当前路径下所有文件夹中的 index.vue
     * 2. 遍历获取到的组件模块
     * 3. 利用 app.component 进行注册
     */
    const components = import.meta.glob('./*/index.vue')
    for (const [fullPath,fn] of Object.entries(components)) {
      const componentName = 'm-' + fullPath.replace('./','').split('/')[0]
      app.component(componentName,defineAsyncComponent(fn))
    }
  }
}
